package o2o.dao.TO.sync;

import com.jinyou.utils.common.DateUtils;
import lombok.Data;
import lombok.experimental.Accessors;
import o2o.cache.company.postman.PostTypeMemory;
import o2o.dao.PO.company.postman.PostTypeInfo;
import o2o.dao.PO.order.ORDER_STATUS;
import o2o.dao.PO.order.OrderInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jahnke【1029777564@qq.com】
 * @ClassName CloudOrderTo_Yiyi
 * @Description: 运行单信息同步
 * @date 2019/8/24 9:39
 * @Version 1.0
 */
@Data
@Accessors(chain = true)
public class CloudOrderTo_Yiyi {

    private Long id;
    private String orderNo;
    private Integer totalCount;
    private Double totalPrice;
    private Double deliveryPrice;
    private Long typeId;                    //
    private Integer preDayNo;               // 每日编号
    private String canGrabCompanyIds;       // 可以接单的公司，多个,分割
    private Double plateAllowance;          // 平台奖励金
    private Integer groupState = 0;     // 聚合订单 0 非聚合订单 1 聚合订单父订单  11 聚合订单子订单

    /********商户信息*********/
    private List<CloudOrderShopTO_Yiyi> shop = new ArrayList<>();

    /********购买人信息*********/
    private String buyer;
    private String username;
    private String telephone;
    private String address;
    private String address2;
    private Double lng;
    private Double lat;
    private String province;
    private String city;
    private String shopCity;
    private String county;

    // 转订单信息
    public OrderInfo convertInfo() {
        // 根据typeId转换typeCode
        PostTypeInfo typeInfo = PostTypeMemory.getInstance().getById(this.getTypeId());
        if (typeInfo == null) {
            System.out.println("配送类型错误-" + this.getTypeId());
            return null;
        }
        OrderInfo order = new OrderInfo();
        BeanUtils.copyProperties(this, order);
        order.setOrderStatus(ORDER_STATUS.SHOP_SURE).setShopSelfPost(0);
        order.setPayOrderNo(this.getOrderNo()).setShopId(0L);
        order.setCreateTime(DateUtils.getCurrTime());
        if (StringUtils.isEmpty(this.getOrderNo())) {
            order.setOrderNo(this.getId().toString());
        }
        order.setOrderType(typeInfo.getType());

        return order;
    }
}
